package com.yangxd.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yangxd.hospital.entity.Registration;
import com.yangxd.hospital.mapper.RegistrationMapper;
import com.yangxd.hospital.service.RegistrationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yangxd
 * @since 2021-05-07
 */
@Service
public class RegistrationServiceImpl extends ServiceImpl<RegistrationMapper, Registration> implements RegistrationService {


    @Autowired
    private RegistrationMapper registrationMapper;
    /**
     * 根据用户id获得所有预约记录
     *
     * @param userId
     * @return
     */
    @Override
    public List<Registration> getHisById(Integer userId) {
        List<Registration> registrationList = new ArrayList<>();
        registrationList = registrationMapper.getListById(userId);
        return registrationList;
    }

    /**
     * 用户插入挂号记录
     * @param registration
     */
    @Override
    public void saveRegistration(Registration registration) {
        registrationMapper.saveRegistration(registration);
    }

    /**
     * 医生获取被预约的记录
     *
     * @param doctorId
     * @return
     */
    @Override
    public List<Registration> getManById(Integer doctorId) {
        List<Registration> registrationList = registrationMapper.getListByDocId(doctorId);
        return registrationList;
    }

    /**
     * 更改预约状态
     *
     * @param status
     */
    @Override
    public void updateStatus(Integer status,Integer registrationId) {
        registrationMapper.updateStatus(status,registrationId);

    }

    /**
     * 分页查询所有挂号记录
     *
     * @param page
     * @param wrapper
     * @return
     */
    @Override
    public IPage<Registration> findPageRegistration(Page<Registration> page, QueryWrapper<Registration> wrapper) {
        return this.baseMapper.findPageRegistration(page,wrapper);
    }

    @Override
    public int selectNum(Integer doctorId) {
        return this.baseMapper.selectNum(doctorId);
    }


}
